<?
require("../../common/init.php");
require("author.php");
require("upfile.php");

$refund_reason=new DB(Trefund_reason,$conn);
$gee=$refund_reason; // gee, 意为赶车时候喊的"驾", 此处用来表示次页面的主角对象 gee=role object
//$cate=$language; // cate = category, 分类
$cateid=0;

$title=ROOT_ORDER_CANCEL_REASON;
$url='refund_reason';
$do=isset($_GET["do"])?clean($_GET["do"]):'view'; // 操作: 查看/编辑/删除 
$action=isset($_POST["action"])?clean($_POST["action"]):''; // 数据库操作: CURD 
$id=0; if (isset($_GET["id"])) $id = clean($_GET["id"]);

// sql action / sql 动作
switch ($action){
	case "update":
		sql_update();
		break;
	case "add":
		sql_insert();
		break;
}

if($id==0){
	$page=1; if(isset($_GET["page"]))if(is_numeric($_GET["page"]))$page=$_GET["page"];
	$order='seq_no';
	$where=array();
	$pages=$gee->count_pages($where);
	$info=$gee->get_page($page,$where,$order);
}
else $info=$gee->get_row($id);


function add()
{
	global $h, $url;
	$row = array(
	);
	echo $h->form($url.'.php', 1, '');
	show_box($row, true, true);
	echo $h->hidden('action', 'add');
	echo $h->former();
}
function update($info)
{
	global $gee, $h, $url, $id;
	if($id=="") 
	{
		echo "Invali argument!!!";
		exit;
	}
	echo $h->form($url.'.php', 1, '');
  	show_box($info, true, false);
	echo $h->hidden('action', 'update');
	echo $h->former();
}
function delete($id)
{
	global $gee,$url;
	$info=$gee->get_row($id);
	if($gee->delete($id)){
		wheel("$url.php");
	}
}	
function show_info($info)
{
	global $id;
	if($id==0)
	{
  	show_boxes($info);
	}
	else 
	{
		show_box($info, false);
	}
}
function sql_insert()
{
	global $gee,$url,$arrlang, $lang;
	$arr=array(
		'seq_no'=>$_POST["seq_no"],
        'name_'.$lang => $_POST['name_'.$lang],
        'type' => $_POST['type']
	);
	if($gee->insert($arr))
	yell(ROOT_ADD_SUCCESS,$url.'.php');
}
function sql_update()
{
	global $gee, $url,$arrlang, $lang;
	$id=$_POST["id"];
	$arr=array(
		'seq_no'=>$_POST["seq_no"],
        'name_'.$lang => $_POST['name_'.$lang],
        'type' => $_POST['type']
	);
	//pre($arr); exit;
	if($gee->update($arr, 'id', $id ) ) {
		yell(ROOT_UPDATE_SUCCESS,$url.'.php');
	}
}

// view 加载视图
require ROOTVIEW.'refund_reason.php';

// end about.php